﻿using System;
using System.Windows.Forms;

namespace Microsoft.WowAddonStudio.Project.OptionPages
{
    public partial class WowBenchGeneralOptionsControl : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="WowBenchGeneralOptionsControl"/> class.
        /// </summary>
        public WowBenchGeneralOptionsControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// WoWBench intstallation folder path.
        /// </summary>
        /// <value>The WoW bench path.</value>
        public string WowBenchPath
        {
            get { return textBoxWowBenchPath.Text; }
            set
            {
                textBoxWowBenchPath.Text = value;
                checkBoxCustomWowBenchPath.Enabled = value != null;
            }
        }

        /// <summary>
        /// Called when [browse_ click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnBrowse_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog())
            {
                dialog.RootFolder = Environment.SpecialFolder.MyComputer;
                dialog.ShowNewFolderButton = false;
                dialog.Description = "Select WoWBench installation folder...";
                dialog.SelectedPath = Environment.CurrentDirectory;

                if (dialog.ShowDialog() == DialogResult.OK)
                    textBoxWowBenchPath.Text = dialog.SelectedPath;
            }
        }

        private void checkBoxCustomWowBenchPath_CheckedChanged(object sender, EventArgs e)
        {
            textBoxWowBenchPath.Enabled = buttonBrowse.Enabled = checkBoxCustomWowBenchPath.Checked;
            if (!checkBoxCustomWowBenchPath.Checked)
                textBoxWowBenchPath.Text = null;
        }
    }
}